package cn.lg.soar.mvc.log;

import cn.lg.soar.core.handler.log.ILogCollector;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Lazy;

/**
 * 默认操作日志处理器
 * @author luguoxiang
 * @date 2022/4/23
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Lazy
@ConditionalOnMissingBean(ILogHandler.class)
public class DefaultLogHandler implements ILogHandler {

    private final ILogCollector collector;

    public DefaultLogHandler(ILogCollector collector) {
        this.collector = collector;
    }

    @Override
    public void log(String operate, Object data, String dataId, String dataType) {
        collector.save(ILogHandler.getLogDTO(operate, data, dataId, dataType));
    }

    @Override
    public void logSync(String operate, Object data, String dataId, String dataType) {
        collector.saveSync(ILogHandler.getLogDTO(operate, data, dataId, dataType));
    }

}
